<template>
  <div class='search'>
    <f-drawer ref='payDetailsDrawer' :show-footer='false' title='部门结算明细' width='87%' @visibleChange='visibleChange'>
      <apply-details ref='form1' :invoiceApply='invoiceApply' :invoiceData="invoiceData" :columns='columns' v-if='drawerVisible'></apply-details>
    </f-drawer>
  </div>
</template>
<script>

import ApplyDetails from "./apply_details"

export default {
  name: "ApplyDetailsDrawer",
  props: {},
  data() {
    return {
      refs: this.$refs,
      drawerVisible: false,
      isEdit: false,
      title: "",
      invoiceApply: 0,
      invoiceData: null,
      current: "form1",
      formData: {},
      columns: null,
      forms: [
        "form1"
      ]
    }
  },
  methods: {
    showDrawer(data) {
      this.formData = data
      this.columns = this.getCol(data)
      this.invoiceApply = data.invoiceApply
      this.invoiceData = data
      this.refs["payDetailsDrawer"].show(data)
      this.$nextTick(() => {
        this.refs["form1"].setData(this.formData)
      })
    },
    handleSubmit(callback) {
      this.refs[this.current].handleSubmit(callback)
    },
    visibleChange(drawerVisible) {
      if (drawerVisible == false) {
        this.$emit("success")
      }
      this.drawerVisible = drawerVisible
    },
    getCol(data) {
      let settleFlag = !(data.settleType == 1)
      let settleFlagD = !(data.settleType == 2)
      let settleFlagC = !(data.settleType == 3)
      let settleFlagE = !(data.settleType == 4)
      return [
        {
          title: "序号",
          width: "60px",
          align: "left",
          fixed: "left",
          dataIndex: "rowIndex",
          customRender: function(text, record, index) {
            return (record.rowIndex !== "合计") ? (parseInt(index) + 1) : record.rowIndex
          }
        },
        {
          title: "单据日期",
          align: "center",
          sorter:true,
          fixed: "left",
          width: "100px",
          dataIndex: "sendDate"
        },
        {
          title: "订单编号",
          align: "center",
          width: "130px",
          fixed: "left",
          dataIndex: "orderNo"
        },
        {
          title: "发货单号",
          align: "center",
          width: "130px",
          fixed: "left",
          dataIndex: "outOrderNo"
        },
        {
          title: "部门名称",
          align: "left",
          sorter:true,
          width: "100px",
          dataIndex: "deptName"
        },
        {
          title: "业务员",
          align: "center",
          width: "100px",
          sorter:true,
          dataIndex: "saleManName"
        },
        {
          title: "业务员编码",
          align: "center",
          sorter:true,
          width: "100px",
          dataIndex: "businessCode"
        },
      
        {
          title: "单位名称",
          align: "left",
          width: "130px",
          sorter:true,
          ellipsis: true,
          dataIndex: "customName"
        },
        {
          title: "商品名称",
          align: "left",
          ellipsis: true,
          sorter:true, 
          width: "140px",
          dataIndex: "drugsName"
        },
        {
          title: "规格",
          align: "left",
          ellipsis: true,
          width: "80px",
          dataIndex: "drugsSpec"
        },
        {
          title: "发货方式",
          align: "center",
          width: "100px",
          dataIndex: "sendType",
          scopedSlots: { customRender: "sendType" }
        },
        {
          title: "类型",
          align: "center",
          width: "80px",
          dataIndex: "drugType",
          scopedSlots: { customRender: "drugType" }
        },
        {
          title: "销售单价",
          align: "center",
          width: "80px",
          dataIndex: "salePrice"
        },
        {
          title: "数量",
          align: "center",
          type:10,
          width: "80px",
          dataIndex: "saleNum"
        },
        {
          title: "销售金额",
          align: "center",
          width: "80px",
          type:10,
          needTotal: true,
          dataIndex: "saleAmount"
        },
        {
          title: "回款金额",
          align: "center",
          type:10,
          width: "80px",
          needTotal: true,
          dataIndex: "returnAmount"
        },
        {
          title: "回款日期",
          align: "center",
          width: "120px",
          dataIndex: "returnDate"
        },
        {
          title: "部门利润",
          align: "center",
          width: "100px",
          type: 10,
          dataIndex: "deptProfitAmount"
        },
        {
          title: "结算标准",
          align: "center",
          width: "100px",
          fixed: "right",
          type: 10,
          dataIndex: "deptRate"
        },
        {
          title: "部门结算价",
          align: "center",
          fixed: "right",
          width: "90px",
          type: 10,
          dataIndex: "deptPrice"
        },
        {
          title: "部门结算金额",
          align: "center",
          width: "100px",
          needTotal: true,
          fixed: "right",
          type: 10,
          dataIndex: "deptSettleAmount"
        },
      ]
    },
    tabClick(name) {
      this.current = name
      this.$nextTick(() => {
        this.refs[this.current].setData(this.formData)
      })
    }
  },
  created() {
  },
  components: { ApplyDetails }
}
</script>

<style scoped lang='less' rel='stylesheet/less'>

</style>
